/**
 * &copy; 2006 NewInstance.it
 */
package it.newinstance.jrainbow.converter;

import it.newinstance.jrainbow.source.TaggedSource;
import it.newinstance.util.Configuration;

import java.io.IOException;

/**
 * @author Luigi R. Viggiano
 * @version $Id: Converter.java 159 2007-11-15 02:33:39Z luigi.viggiano $
 */
public interface Converter {

	public abstract void convert(TaggedSource source) throws IOException;

	public final static class Factory {
		private static final Configuration conf = Configuration
				.getConfiguration(Converter.class);

		private Factory() {
		}

		/**
		 * Return a converter to a specific format for a given language.
		 * 
		 * @param language
		 *            the language of the wanted converter
		 * @param format
		 *            the format of the resulting conversion
		 * @return a converter to specified format for the given language
		 * @throws UnsupportedConverterException
		 *             when the requested converter could not be created
		 */
		@SuppressWarnings("unchecked")
		public static Converter newInstance(String language, String format)
				throws UnsupportedConverterException {
			String converterName = language + ".to." + format;
			String converterClassName = conf.getString(converterName);
			try {
				return ((Class<Converter>) Class.forName(converterClassName))
						.newInstance();
			} catch (Exception e) {
				throw new UnsupportedConverterException(language + " to "
						+ format, e);
			}
		}
	}
}
